package logic

import (
	"context"
	"gorm.io/gorm"
	"user/models/mysql"
	"user/pkg"

	"user/userrpc/internal/svc"
	"user/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRealLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealLogic {
	return &RealLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RealLogic) Real(in *userrpc.RealRequest) (*userrpc.RealResponse, error) {
	// todo: add your logic here and delete this line

	pkg.RealName(in.RealName, in.IdCard)

	user := mysql.User{
		Model: gorm.Model{ID: uint(in.Id)},

		RealName: in.RealName,
		IdCard:   in.IdCard,
	}
	mysql.DB.Debug().Updates(&user)
	return &userrpc.RealResponse{
		RealId: int64(user.ID),
	}, nil
}
